/**
 *  链表：p->n1->n2
    n1 = p.next
    n2 = p.next.next
    p.next = n2
    n1.next = n2.next
    n2.next = n1
    p = n1
 */
/**
 * example：1->2->3->4 ==> 2->1->4->3
 * @param head 链表的头 
 */
var swapPairs = function (head) {
    // 创建哨兵节点，方便第一个元素的操作
    let dummy = new ListNode()
    dummy.next = head

    let current = dummy
    // n1和n2都不为空
    while (current.next !== null && current.next.next !== null) {
        let n1 = current.next
        let n2 = current.next.next
        current.next = n2
        n1.next = n2.next
        n2.next = n1
        current = n1
    }
    
    return dummy.next
}